package captcha;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Bitmap {
	private Map<Coordinate,Color> map;

	public Map<Coordinate, Color> getMap() {
		return map;
	}

	public Bitmap(Map<Coordinate, Color> map) {
		super();
		this.map = map;
	}
	
	public Map<Coordinate,Color> getNeightbourPixel(Coordinate root) {
		Map<Coordinate,Color> neightbours = new HashMap<Coordinate,Color>();
		for (Entry<Coordinate,Color> e:map.entrySet()) {
			if (e.getKey().x >= root.x-1 && e.getKey().x <= root.x+1 &&
					e.getKey().y >= root.y-1 && e.getKey().y <= root.y+1)
				neightbours.put(e.getKey(), e.getValue());
		}
		return neightbours;
	}
	public List<Coordinate> getTrueNeightbourPixel(Coordinate root) {
		List<Coordinate> trueNeightbours = new ArrayList<Coordinate>();
		for (Entry<Coordinate,Color> e:getNeightbourPixel(root).entrySet()) {
			if (e.getValue().toBoolean())
				trueNeightbours.add(e.getKey());
		}
		return trueNeightbours;
	}
	public Boolean isBorderPart(Coordinate root) {
		if (map.get(root).toBoolean()) {
			return getTrueNeightbourPixel(root).size() == 8;
		}
		else {
			return getTrueNeightbourPixel(root).size() == 0;
		}
	}
}
